package org.red5.demo;


import lombok.extern.slf4j.Slf4j;

import org.red5.daemon.TVideoPara;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @author 武玉锋
 * @Title: ScheduledService.java
 * @Description: Scheduled定时任务实例 ，异步处理 ,启用lombok 工具
 * @date 2019-05-16
 */
@Component
@Slf4j
public class ScheduledService {

    /********************************************************************/
    /**************************    定时任务    ***************************/
    /********************************************************************/

    @Async //异步执行
    @Scheduled(initialDelay = 3060, fixedRate = 30 * 1000)
    public void videoPush() {
        List<TVideoPara> list = ParameterAPI.sVideoRepository.findAll();
        for (TVideoPara videoPara : list) {
            if("流服务器".equals(videoPara.getVender())) {
                if (ParameterAPI.VideoMap.get(videoPara.getLanIpaddr()) == null) {
                    String ip = videoPara.getLanIpaddr();
                    String name = videoPara.getLoginName();
                    String passworld = videoPara.getLoginPassworld();
                    String type = videoPara.getDataRateType();
                    String vender = videoPara.getVender();
                    new Thread(new Runnable() {
                        public void run() {
                            try {
                                if("1".equals(PushRTMP.videoFormat)) {
                                    PushRTMP.runTCP(ip, name, passworld, type,vender);
                                }else if("2".equals(PushRTMP.videoFormat)){

                                    PushRTMP.runUDP(ip, name, passworld, type,vender);
                                }else if("3".equals(PushRTMP.videoFormat)) {
                                    PushRTMP.runCMD(ip, name, passworld, type,vender);
                                }
                              //  PushRTMP.runCMD(ip, name, passworld, type);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }).start();
                }
            }
        }
    }


}